﻿using AutoMapper;
using MediatR;
using S.PurchaseAndSales.Domain.Model;
using S.PurchaseAndSales.Infrastructure.Interface.PurchaseForm;
using S.PurchaseAndSales.Read.Api.Application.Command.PurchaseFormCommand;
using S.PurchaseAndSales.Read.Api.Dto;

namespace S.PurchaseAndSales.Read.Api.Application.CommandHandlers.PurchaseFormHandler
{
    public class PurchaseFormGetByIdCommandHandler : IRequestHandler<PurchaseFormGetByIdCommand, PurchaseFormGetByIdDto>
    {
        #region 注入
        private readonly IPurchaseFormRepository repository;
        private readonly IMapper mapper;
        #endregion

        public PurchaseFormGetByIdCommandHandler(IPurchaseFormRepository repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        public async Task<PurchaseFormGetByIdDto> Handle(PurchaseFormGetByIdCommand request, CancellationToken cancellationToken)
        {
            return mapper.Map<PurchaseFormGetByIdDto>(await repository.GetByIdAsync(request.PurchaseFormId));
        }
    }
}
